﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="UploadVi.ascx.vb" Inherits="Control_MSDS_UploadVi" %>

<script type="text/javascript">
    function ajaxJquery() {
        // focus textbox first
        $(".TextBox:first").focus();

        // Init Autocomplete for textBox ItemCode
        /// Set AutoComplete for UNII
        $("#txtItemcode").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: '<%=ResolveUrl("~/Services/wsAutoComplete.asmx/GetAutoCompleteVendor")%>',
                    data: "{ 'strSrc': '" + request.term.trim() + "'}",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    beforeSend: function () {
                    },
                    dataFilter: function (data) {
                        return data;
                    },
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                label: item.FullText, value: item.ID
                            }
                        }))
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //Alertbox(textStatus);
                    },
                    complete: function () {
                    }
                });
            },
            focus: function (event, ui) {
                $(this).val(ui.item.value);
                return false;
            },
            select: function (event, ui) {
                var _itemCode = ui.item.value;
                $(this).val(_itemCode);
                $("#hidItemCode").val(_itemCode);
                $("#txtItemname").val(ui.item.label);
                setTimeout(FilterVendorCode(_itemCode), 1000);
                return false;
            },
            minLength: 1
        });
        // handler event click load data
        $("#btnSelectFile").click(function () {
            $("#<%= flDocument.ClientID%>").click();
        });
        $("#txtFileUploadName").bind("click", function () {
            $("#<%= flDocument.ClientID%>").click();
        });

        // Check divVendorCode has html ==> show again
        if ($("#drpVendorCode").data("html") != undefined && $("#drpVendorCode").data("html") != "undefined") {
            var _htmlRender = $("#drpVendorCode").data("html");
            $("#drpVendorCode").html(_htmlRender);
        }
        else {
            // Create DropDowList 
            FilterVendorCode($("#hidItemCode").val());
            // select item by value 
            setTimeout(function () { $("#drpVendorCode option:contains(" + $("#hidVendorCode").val() + ")").attr('selected', 'selected') }, 1000);
        }

    } //********************** END INNIT FUNCTION ***************************


    function ResetDataControl() {
        //Alertbox('Hệ thống sẽ tiến hành xử lý dữ liệu của file.');
        $("#<%=txtFileUploadName.ClientID%>").val('');
        if ($("#<%=flDocument.ClientID%>").val().trim() != "") {
            $("#<%=txtFileUploadName.ClientID%>").val($("#<%=flDocument.ClientID%>").val().trim());
        }
    }
    // function Ajax filter Vendor Code by ItemCode
    function FilterVendorCode(_itemCode) {
        $.ajax({
            url: '<%=ResolveUrl("~/Services/wsAutoComplete.asmx/GetListVendor")%>',
            data: "{ 'itemCode': '" + _itemCode + "'}",
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            beforeSend: function () {

            },
            dataFilter: function (data) {
                return data;
            },
            success: function (data) {
                if (data.d != null) {
                    var _html = "<option value='0'> --- Chọn --- </option>";
                    $.each(data.d, function (idx, obj) {
                        _html += ("<option value='" + obj.FullText + "'>" + obj.ID + "</option>");
                    });
                    //var _htmlRender = $("<select class='DropDownList' onchange = 'SetVendorCode(this);'>").append(_html);
                    //$("#divVendorCode").data("html", _htmlRender)
                    //$("#divVendorCode").html(_htmlRender);
                    $("#drpVendorCode").data("html", _html)
                    $("#drpVendorCode").html(_html);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //Alertbox(textStatus);
            },
            complete: function () {
            }
        });
        return true;
    }

    // Function set Vendor Code and vendorName
    function SetVendorCode(obj) {
        $("#hidVendorCode").val(obj.options[obj.selectedIndex].text);
        $("#txtVendorname").val(obj.value);

    }
    // Check Valid Form
    function CheckValid() {

        var itemCode = $("#hidItemCode").val();
        var vendorCode = $("#hidVendorCode").val();
        // Check  
        if (itemCode == "") {
            error += "<li>Vui lòng nhập Item Code</li>";
            countbug += 1;
        }

        if (vendorCode * 0 == 0) {
            error += "<li>Vui lòng chọn Vendor Code</li>";
            countbug += 1;
        }
        if (countbug >= 1) {
            //remove all old error
            $('#lstErrorContent li').remove();
            //show new list bug
            $("#lstErrorContent").append(error);
            $('html, body').animate({ scrollTop: $(".Error").height() }, 800);
            return false;
        }
        $("#UpdateProgress1").css({ display: "block" });
        return true;
    }
</script>



<div class="BoxField">
	<div style="clear: both; padding-top: 10px;">
	</div>
	<div class="DivRow">
		<div class="HeadTitle">
			<h3>Cập nhật bản dịch MSDS
			</h3>
		</div>
		<div style="clear: both">
		</div>
		<div class="lblEdit">
			<span class="fieldRequired">&nbsp;</span>Trường yêu cầu nhập dữ liệu
		</div>
		<div class="Error-Center">
			<div id="divError">
				<ul id="lstErrorContent">
				</ul>
			</div>
		</div>
	</div>

	<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="Label1" CssClass="TextLabel" runat="server" Text="File Vi:" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtFileUploadName" runat="server" CssClass="TextBox" MaxLength="200"
				ClientIDMode="Static"></asp:TextBox>
			<input id="btnSelectFile" type="button" value="Browse . . ." class="btn" />
			<asp:FileUpload ID="flDocument" runat="server" CssClass="TextBox" Height="22px" Style="display: none"
				onchange="javascript:return ResetDataControl();" />
		</div>
	</div>

	<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="lblItemcode" CssClass="TextLabel" runat="server" Text="Item Code:" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtItemcode" CssClass="TextBox" runat="server" Text="" ClientIDMode="Static" Enabled=false />
			<asp:HiddenField runat="server" ID="hidItemCode" Value="" ClientIDMode="Static" />
		</div>
	</div>
	<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="lblItemname" CssClass="TextLabel" runat="server" Text="Item Name:" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtItemname" CssClass="TextBox" runat="server" Text="" ClientIDMode="Static" Enabled="false" />
		</div>
	</div>
	<div class="DivRow" style="height: 30px">
		<div class="DivLabel">
			<asp:Label ID="lblVendorcode" CssClass="TextLabel" runat="server" Text="Vendor Code:" />
		</div>
		<div class="DivTextBox" id="divVendorCode">
			<select id="drpVendorCode" class='DropDownList' onchange='SetVendorCode(this);' disabled="disabled" >
				<option value="0">--- Chọn ---</option>
			</select>
		</div>
		<asp:HiddenField ID="hidVendorCode" runat="server" Value="" ClientIDMode="Static" />
	</div>
	<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="lblVendorname" CssClass="TextLabel" runat="server" Text="Vendor Name:" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtVendorname" CssClass="TextBox" runat="server" Text="" ClientIDMode="Static" Enabled="false" />
		</div>
	</div>
	<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="lblOriginal" CssClass="TextLabel" runat="server" Text="Original:" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtOriginal" CssClass="TextBox" runat="server" Text="" ClientIDMode="Static" Enabled="false" />
		</div>
	</div>

	<div style="clear: both; height: 30px">
	</div>
	<div class="DivRow">
		<div class="DivLabel">
			&nbsp;&nbsp;&nbsp;
		</div>
		<div class="DivTextBox">
			<div style="float: left">
				<asp:Button ID="btnSave" runat="server" Text=" Lưu " CssClass="btn" OnClientClick="return CheckValid()" />
				&nbsp;<asp:Button ID="btnReset" runat="server" CausesValidation="false" CssClass="btn"
					Text="Làm lại" />
			</div>
			<div style="float: right; text-align: right">
				&nbsp;<asp:ImageButton ID="btnBack" ImageAlign="AbsMiddle" ToolTip="Quay lại" runat="server"
					ImageUrl="~/images/back.png" />
			</div>
		</div>
	</div>
</div>
<div style="display: none">
	<asp:HiddenField ID="hidID" Value="0" runat="server" ClientIDMode="Static" />
	<asp:HiddenField ID="hidOldFile" Value="" runat="server" ClientIDMode="Static" />
</div>
